function initPlugin() {
    // 初始化日期插件
    jeDate("#articleDate", {
        format: "YYYY-MM-DD ",
        isinitVal: true
    })

    // 初始化富文本插件
    tinymce.init({
        selector: "#articleContent",
        language: 'zh_CN',
    })
};

initPlugin();

// 从服务器获取所有分类
function getCategory() {
    http.ajax({
        type: "get",
        url: "/admin/category/list",
        success: (res) => {
            const renderResult = template('categoryTemplate', res);
            $(".category").html(renderResult);
        }
    });
}
getCategory();

// 图片上传预览
$('#inputCover').on("change", () => {
    const file = $("#inputCover")[0].files[0];
    if (file) {
        const url = URL.createObjectURL(file);
        $(".article_cover").prop("src", url);
    }
});



//发布文章/草稿
function publishArticle(state) {
    const formData = new FormData($("#form").get(0));
    formData.append("state", state);
    const content = tinymce.activeEditor.getContent();
    formData.set("content", content);
    for (let item of formData.entries()) {
        console.log(item);
    }
    http.ajax({
        type: "post",
        url: "/admin/article/publish",
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code === 200) {
                alert(res.msg);
            }
        }
    });
    return false;
}